//
//  STTabBarController.m
//  ShaBaoOnLine
//
//  Created by huang yong on 16/7/7.
//  Copyright © 2016年 com.ShaBaoOnline.www. All rights reserved.
//

#import "STTabBarController.h"
#import "STNavigationController.h"
#import "StoreViewController.h"
#import "OrderListViewController.h"

#import "STTabBar.h"
#define StoreViewControllerID @"StoreViewController"

#define OrderListViewControllerID @"OrderListViewController"

@interface STTabBarController ()<STTabBarHandlerDelegate>
@property(nonatomic ,assign)NSInteger bageValue;

@end

@implementation STTabBarController

+ (void)initialize{
    UITabBarItem *tabBarItem = [UITabBarItem appearance];
    
    NSMutableDictionary *dictNormal = [NSMutableDictionary dictionary];
    dictNormal[NSForegroundColorAttributeName] = [UIColor grayColor];
    dictNormal[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    NSMutableDictionary *dictSelected = [NSMutableDictionary dictionary];
    dictSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    dictSelected[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    [tabBarItem setTitleTextAttributes:dictNormal forState:UIControlStateNormal];
    [tabBarItem setTitleTextAttributes:dictSelected forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
 
    //设置子控制器
    [self setupChildVC];
    
    STTabBar *tabBar = [[STTabBar alloc] init];
    tabBar.mydelegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
    
    
}

- (void)setupChildVC{
    StoreViewController *homeVc = [[UIStoryboard storyboardWithName:StoreViewControllerID bundle:nil] instantiateViewControllerWithIdentifier:StoreViewControllerID];
    [self setupController:homeVc image:@"home_normal" seletedImage:@"home_highlight" title:@"店铺"];
    
    OrderListViewController *messageVc = [ UIStoryboard loadStoryboard:OrderListViewControllerID];
    [self setupController:messageVc image:@"message_normal" seletedImage:@"message_highlight" title:@"订单"];
    
//    STRemindTVC *remindTVc = [[UIStoryboard storyboardWithName:@"Remind" bundle:nil] instantiateViewControllerWithIdentifier:@"STRemindTVC"];
//    _remindTVc =remindTVc;
//    [self setupController:remindTVc image:@"remind_normal" seletedImage:@"remind_highlight" title:@"提醒"];
//    STMineController *mineVc = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil]instantiateViewControllerWithIdentifier:@"STMineController"];
//    [self setupController:mineVc image:@"mine_normal" seletedImage:@"mine_highlight" title:@"我的"];
}

- (void)setupController:(UIViewController *)Vc image:(NSString *)image seletedImage:(NSString *)selImge title:(NSString *)title{
    STNavigationController *navVc = [[STNavigationController alloc] initWithRootViewController:Vc];
    
    Vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    Vc.tabBarItem.selectedImage = [[UIImage imageNamed:selImge] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    Vc.tabBarItem.title = title;
    [self addChildViewController:navVc];
}

//- (void)addBtnClickHandler{
//    STAddController *addVc = [[STAddController alloc] init];
//    addVc.segmentBgColor = [UIColor colorWithRed:18.0f/255 green:50.0f/255 blue:110.0f/255 alpha:1.0f];
//    addVc.indicatorViewColor = [UIColor whiteColor];
//    addVc.titleColor = [UIColor whiteColor];
//    STAddCompanyCustomerVC *companyVC = [STAddCompanyCustomerVC new];
//    STAddPresonController *presonVc = [[STAddPresonController alloc] init];
//    
//    [addVc setViewControllers:@[companyVC, presonVc]];
//    [addVc setTitles:@[@"新增企业客户", @"新增个人客户"]];
//    [addVc setIndexVCIndex:0];
//    [addVc.segment setSelectedIndex:0];
//    STNavigationController *navVc = [[STNavigationController alloc] initWithRootViewController:addVc];
//    
//    [self presentViewController:navVc animated:YES completion:nil];
//}
//-(void)getRemindListFromNetworking{
//    NSDate *date = [NSDate new];
//    NSDateFormatter *formatter = [NSDateFormatter new];
//    formatter.dateFormat = @"yyyyMM";
//    NSString *dateStr = [formatter stringFromDate:date];
//    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
//    requestParameter[@"salerId"] =loginSalerInfo.ID;
//    requestParameter[@"month"] = dateStr;//@"201608";
//    requestParameter[@"token"] = token;
//    __weak typeof(self) weakSelf = self;
//    [[STNetworkRequest shareRequest] startGetRequest:api_get_remind parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
//        int result = [[jsonResponse objectForKey:@"result"]intValue];
//        if (1 == result) {
//            STRemindListModel *remindListModel = [STRemindListModel pareRemindList:jsonResponse];
//            weakSelf.bageValue = remindListModel.remindModelArr.count;
//            //设置续费提醒条数
//            if (weakSelf.bageValue != 0) {
//                _remindTVc.tabBarItem.badgeValue= [NSString stringWithFormat:@"%lu",self.bageValue];
//            }
//        }
//    } onError:^(id jsonResponse) {
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        [MBProgressHUD showError:@"暂无网络"];
//    }];
//}
@end
